package com.wk.springboot.config;

import java.util.HashSet;
import java.util.Set;
import org.springframework.cache.Cache;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Classname CacheConfig
 * @Description cache配置类
 * @Date 2020/7/9 16:01
 * @Author by weikai
 */

@Configuration
public class CacheConfig {

  @Bean
  public SimpleCacheManager cacheManager() {
    SimpleCacheManager simpleCacheManager = new SimpleCacheManager();

    ConcurrentMapCache defaultCache = new ConcurrentMapCache("default");
    ConcurrentMapCache userCache = new ConcurrentMapCache("user");

    Set<Cache> set = new HashSet();
    set.add(defaultCache);
    set.add(userCache);

    simpleCacheManager.setCaches(set);

    return simpleCacheManager;
  }
}
